<template>
  <div class="warning_container">
    <!-- 标题 -->
    <div class="top_box">
      <span class="warning_title">报 警 信 息</span>
      <span class="open_warning_details" @click="openWarningDetails">查看详情</span>
    </div>
    <!-- 内容 -->
    <div class="warning_content">
      <div class="warning_contents">
        <el-table
          :data="warningData"
          border
          fit
          highlight-current-row
          @row-contextmenu="rowContextmenu"
          @row-dblclick="dblClickRow"
        >
          <el-table-column prop="LICENSE_PLATE" label="车辆" width="100" align="center"></el-table-column>
          <el-table-column prop="TYPE" label="报警类型" min-width="120" align="center"></el-table-column>
          <el-table-column sortable prop="ALARMTIME" label="报警时间" min-width="110" align="center"></el-table-column>
          <el-table-column prop="LONGITUDE" label="经度" align="center" width="120" :formatter="formatter"></el-table-column>
          <el-table-column prop="LATITUDE" label="纬度" align="center" width="120" :formatter="formatter"></el-table-column>
        </el-table>
      </div>
      <!-- <div class="pages">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pageSize"
        layout="prev, pager, next"
        :total="warningData.length"
      ></el-pagination>
    </div> -->
    </div>

    <div
      class="rowContextmenu"
      v-if="rowMenu.isShow"
      :style="`top: ${rowMenu.top}px; left: ${rowMenu.left}px`"
    >
      <span @click="exportExcel">导出Excel</span>
      <span>解除报警</span>
      <span>删除图标</span>
    </div>
  </div>
</template>

<script>
import eventBus from '@/eventBus.js'

import export2Excel from '@/utils/exportExcel/index.js'

export default {
  data () {
    return {
      warningData: [],
      warningDetailList: [],
      rowMenu: {
        top: 0,
        left: 0,
        isShow: false
      },
      row: null,
      personWarning: null,
      dialogFormVisiblePayment:false,
      formLabelWidth: "100px",
      // 默认显示第几页
      currentPage: 1, // 当前页码
      totalCount: 20, // 总条数
      pageSize: 4, // 每页的数据条数
    }
  },
  created () {
    this.getWarningList()
    this.getWarningDetailList()
  },
  methods: {
    // 报警信息
    async getWarningList () {
      var url = '/DataListCompany/GetVehicleAlarmCCApi?CLIENT_NO=' + localStorage.getItem('CLIENT_NO') + '&NUM=100'
      const { data } = await this.$Http.get(url)
      this.warningData = data
      // eventBus.$emit('warningData', this.warningData)
    },
    // 报警详情信息
    async getWarningDetailList () {
      var url = '/DataListCompany/GetVehicleAlarmDetailCCApi?CLIENT_NO=' + localStorage.getItem('CLIENT_NO') + '&NUM=100&ID=0'
      const { data } = await this.$Http.get(url)
      this.warningDetailList = data
      eventBus.$emit('warningData', this.warningDetailList)
    },
    // 打开报警详情
    openWarningDetails () {
      eventBus.$emit('warningDetails', true)
    },
    // 右键某一行
    rowContextmenu (row, column, event) {
      this.row = row
      window.event.returnValue = false
      this.rowMenu.isShow = true
      this.rowMenu.top = event.clientY
      this.rowMenu.left = event.clientX
      const x = document.body.clientWidth - event.clientX
      if (x < 100) this.rowMenu.left = event.clientX - 100
    },
    // 双击某一行
    dblClickRow (row, column, event) {
      // eventBus.$emit('warningItem', row)
      this.getWarningDetail(row.ID, row.LONGITUDE, row.LATITUDE)
    },
    // 报警详情信息
    async getWarningDetail (alarmID, alarmLON, alarmLAT) {
      var url = '/DataListCompany/GetVehicleAlarmDetailCCApi?CLIENT_NO=' + localStorage.getItem('CLIENT_NO') + '&NUM=100&ID=' + alarmID
      const { data } = await this.$Http.get(url)
      const val = data[0]
      val["LONGITUDE"] = alarmLON
      val["LATITUDE"] = alarmLAT
      eventBus.$emit('warningItem', val)
    },
    // 导出Excel
    exportExcel () {
      this.rowMenu.isShow = false
      const excelName = this.row.NAME + '-报警信息'
      const tHeader = ['姓名', '报警类型', '报警位置', '报警时间', '经度', '纬度']
      const filterVal = ['NAME', 'ALARM_TYPE', '', 'ALARM_DATE', 'LONGITUDE', 'LATITUDE']
      const ary = []
      ary.push(this.row)
      export2Excel(tHeader, filterVal, ary, excelName)
    },
    // 格式化单元格内容
    formatter (row, column, cellValue, index) {
      // console.log(cellValue)
      if (cellValue === 0) return ' '
      if (cellValue !== 0) return cellValue
    },
    // 鼠标进入单元格显示其内容
    cellMouseEnter (row, column, cell, event) {
      cell.setAttribute('title', cell.innerText)
    }
  }
}
</script>

<style scoped lang="less">
.warning_container {
  width: 100%;
  height: 100%;
  border-left: 4px solid #007ACC;
}
.top_box {
  background-color: #fff;
  height: 36px;
  line-height: 30px;
  border-bottom: 2px solid #007ACC;
  border-top: 2px solid #007ACC;
  padding-left: 66px;
  display: flex;
  align-items: center;
  .iconfont {
    cursor: pointer;
  }
  .warning_title {
    margin: 0 auto;
    font-weight: bold;
    cursor: default;
  }
  .open_warning_details {
    float: right;
    margin-right: 10px;
    color: #666;
    cursor: pointer;
    &:hover {
      color: #007ACC;
    }
  }
}

.warning_content {
  display: flex;
  height: calc(~"100% - 30px");
  .warning_contents {
    width: 100%;
    // overflow-x: hidden;
    // overflow-y: auto;
    .el-table {
      height: 100%;
    }
    /deep/.el-table__body-wrapper {
      height: calc(~"100% - 33px");
      overflow-y: auto;
    }
  }
}
.details {
  width: 600px;
  height: 400px;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  position: fixed;
  z-index: 99;
}
.rowContextmenu {
  width: 100px;
  height: 78px;
  background-color: #f3f3f3;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 999;
  span {
    display: block;
    text-align: center;
    line-height: 26px;
    font-size: 12px;
    cursor: default;
    &:hover {
      background-color: #007ACC;
      color: #fff;
    }
  }
}
</style>
